package com.example.demo.controller;

import com.example.comon.domain.R;
import com.example.demo.domain.Attendance;
import com.example.demo.domain.Bo.AddAttendanceBo;
import com.example.demo.domain.Bo.AttendanceBo;
import com.example.demo.domain.Vo.AttendanceVo;
import com.example.demo.service.IAttendanceService;
import com.example.demo.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/attendance")
@Api(value = "attendance" , tags = "考勤控制器")
public class AttendanceController {

    @Autowired
    private IAttendanceService attendanceService;

    @GetMapping("/getAttendance")
    @ApiOperation("获取考勤列表")
    public R<List<AttendanceVo>> getAttendance(AttendanceBo bo){
        Attendance attendance = new Attendance();
        attendance.setEmployeeId(bo.getEmployeeId());
        List<AttendanceVo>list = attendanceService.selectAttendance(attendance);
        return R.success(list);
    }

    @PostMapping("/addAttendance")
    @ApiOperation("新增考勤")
    public R<Attendance> addAttendance(@RequestBody AddAttendanceBo bo){
        Attendance attendance = new Attendance();
        attendance.setEmployeeId(bo.getEmployeeId());
        attendance.setPunchType(bo.getPunchType());
        attendance.setPunchTime(bo.getPunchTime());
        attendance.setState(bo.getState());
        attendanceService.insertAttendance(attendance);
        return R.success(attendance);
    }

    @PostMapping("/updateAttendanceById")
    @ApiOperation("修改考勤")
    public R updateAttendanceById(@RequestBody Attendance attendance){
        attendanceService.updateAttendanceById(attendance);
        return R.success();
    }

    @DeleteMapping("/delAttendanceById")
    @ApiOperation("删除考勤")
    public R delAttendanceById(long attendanceId){
        attendanceService.delAttendanceById(attendanceId);
        return R.success();
    }
}
